package OOAE_UWE.Assessment;
import java.util.Date;
// Abstract Factory
public abstract class RentalAgreementFactory {
    protected String leaseNumber;
    protected Student student;
    protected Date startDate;
    protected Date endDate;
    private static int leaseCounter = 1; // generate lease number
    public RentalAgreement createAgreement(Room room) throws InvalidConditionException {
        validateRoomCondition(room);
        leaseNumber = "LN" + leaseCounter++; // generate lease number automatically
        return createRentalAgreement(room);
    }
    protected void validateRoomCondition(Room room) throws InvalidConditionException {
        //****check if rented or not
        if (room.isRented()) {
            throw new InvalidConditionException("Cannot create agreement: Room is already rented.");
        }

        //check the room state type
        if (!(room.getCurrentState() instanceof CleanState)) {
            throw new InvalidConditionException(
                    "Cannot create agreement: Room status is " + room.getCurrentState()
            );
        }
    }
    protected abstract RentalAgreement createRentalAgreement(Room room);
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
}








